package com.nstar.uecenter.view.main.impl
{
	import com.nstar.base.util.LoadXMLDelegate;
	import com.nstar.base.util.Logger;
	import com.nstar.base.util.SystemUtils;
	import com.nstar.uecenter.view.components.PopUpTips;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.system.System;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	
	import mx.containers.HBox;
	import mx.controls.Button;
	import mx.controls.Text;
	import mx.effects.Blur;
	import mx.effects.Move;
	import mx.effects.Parallel;
	import mx.events.FlexEvent;
	import mx.rpc.IResponder;

	public class ContactUsClass extends HBox  implements IResponder
	{
		
		public var txtContactUs:Text;
		
		private var loader:LoadXMLDelegate ;
		private var logger:Logger = Logger.getInstance();	
		
		public var btnKomaMobile:Button;
		public var btnKomaMail:Button;
		public var btnKomaQQ:Button;
		
		public var btnZhucmMobile:Button;
		public var btnZhucmMail:Button;
		public var btnZhucmQQ:Button;
		
			
		public function ContactUsClass()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			//loadContactUs();
			btnKomaMobile.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnKomaMobile.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
			
			btnKomaMail.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnKomaMail.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
			btnKomaMail.addEventListener(MouseEvent.CLICK,mailKomaHandler);
			
			btnKomaQQ.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnKomaQQ.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
			btnKomaQQ.addEventListener(MouseEvent.CLICK,qqKomaHandler);


			btnZhucmMobile.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnZhucmMobile.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
			btnZhucmQQ.addEventListener(MouseEvent.CLICK,qqZhucmHandler);
			
			btnZhucmMail.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnZhucmMail.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
			btnZhucmMail.addEventListener(MouseEvent.CLICK,mailZhucmHandler);
			
			btnZhucmQQ.addEventListener(MouseEvent.ROLL_OVER,rolloverHandler);
			btnZhucmQQ.addEventListener(MouseEvent.ROLL_OUT,rolloutHandler);
		}	
		
		private var par:Parallel = new Parallel();
		private var interval:uint =0;
		private var oldx:Number = 0;
		private var oldy:Number = 0;
		
		private function rolloverHandler(event:MouseEvent):void{
			oldx = event.target.x;
			oldy = event.target.y;
			interval = setInterval(randomMoveHandler,100,event.target);
		}	

		private function rolloutHandler(event:MouseEvent):void{
			par.end();
			event.target.x = oldx;
			event.target.y = oldy;
			clearInterval(interval);
			PopUpTips.hide();
		}	
		
		private function mailKomaHandler(event:MouseEvent):void{
			//navigateToURL(new URLRequest("mailto:zhuchuanming@gmail.com"),"_blank");
			var mail:String = "komayangtao@gmail.com";
			System.setClipboard(mail);
			PopUpTips.show("复制","邮件地址已经复制到剪切板",200,60);
		}
		

		private function mailZhucmHandler(event:MouseEvent):void{
			//navigateToURL(new URLRequest("mailto:zhuchuanming@gmail.com"),"_blank");
			var mail:String = "zhuchuanming@gmail.com";
			System.setClipboard(mail);
			PopUpTips.show("复制","邮件地址已经复制到剪切板",200,60);			
		}
		
		private function qqKomaHandler(event:MouseEvent):void{
			var mail:String = "740800782";
			System.setClipboard(mail);
			PopUpTips.show("复制","QQ号码已经复制到剪切板，您可以在QQ中查找用户。",
				200,80);
		}
		
		private function qqZhucmHandler(event:MouseEvent):void{
			var mail:String = "58049870";
			System.setClipboard(mail);
			PopUpTips.show("复制","QQ号码已经复制到剪切板，您可以在QQ中查找用户。",
				200,80);
		}		

		private function randomMoveHandler(target:Object):void{
			par.target = target;
			
			if(par.children && par.children.length>0){
				Move(par.children[0]).xFrom = SystemUtils.randRange(oldx,oldx+8);
				Move(par.children[0]).yFrom = SystemUtils.randRange(oldy,oldy+8);
				Move(par.children[0]).xTo = SystemUtils.randRange(oldx,oldx+8);
				Move(par.children[0]).yTo = SystemUtils.randRange(oldy,oldy+8);
				par.play();
				return;
			}
			
			
			par.duration = 100;
			
			var m:Move = new Move();
			m.xFrom = SystemUtils.randRange(oldx,oldx+8);
			m.yFrom = SystemUtils.randRange(oldy,oldy+8);
			m.xTo = SystemUtils.randRange(oldx,oldx+8);
			m.yTo = SystemUtils.randRange(oldy,oldy+8);
			var blur:Blur = new Blur();
			
			par.addChild(m);
			par.addChild(blur);
			par.play();
		}
		
		//加载实验产品数据
		private function loadContactUs():void{
			loader = new LoadXMLDelegate(this,"demo/data/ContactUs.xml","object");
			loader.load();
		}
		
		public function result( rpcEvent : Object ) : void
		{
			// call the helper class for parse the XML data
			var desc:Object = rpcEvent.result.about.desc;
			txtContactUs.text = desc.toString();
			trace("load AboutUs ok!");
		}
		
		// this is called when the delegate receives a fault from the service
		public function fault( rpcEvent : Object ) : void 
		{
			trace("load AboutUs error!!!");
		}		
	}
}